package order

import (
	"API/client"
	"API/response"
	"common/utils"
	"fmt"
	"github.com/gin-gonic/gin"
	order "order_server/proto"
)

// todo:回调支付
func OrderUpdatePaid(c *gin.Context) {
	orderSn := c.Request.FormValue("out_trade_no")
	orderStatus := c.Request.FormValue("trade_status")
	var paid int64
	switch orderStatus {
	case "TRADE_SUCCESS":
		paid = 1
	case "TRADE_FINISHED":
		paid = 2
	case "WAIT_BUYER_PAY":
		paid = 3
	case "TRADE_CLOSED":
		paid = 4
	}
	updatePaid, err := client.OrderUpdatePaid(c, &order.OrderUpdatePaidRequest{
		OrderId: orderSn,
		Paid:    paid,
	})
	if err != nil {
		response.CurrencyErrResponse(c, -1, utils.CutOutRpcError(err.Error()))
		return
	}
	c.String(200, "success")
	fmt.Println("回调成功", updatePaid)
}
